// ==UserScript==

// @name StatReadable

// @namespace http://www.broom9.com

// @include http://*.statcounter.com/project/standard/pageload.php*

// ==/UserScript==

/**
	Copied from Prototype.js....
*/
var Try = {
  these: function() {
    var returnValue;

    for (var i = 0, length = arguments.length; i < length; i++) {
      var lambda = arguments[i];
      try {
        returnValue = lambda();
        break;
      } catch (e) {}
    }

    return returnValue;
  }
}

var allLinks, thisLink;
var oldHTML, newHTML;

allLinks = document.evaluate(
"//td[@class='tableContent1Left']/a[@target='_blank']|\
//td[@class='tableContent2Left']/a[@target='_blank']", 
document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
for (var i = 0; i < allLinks.snapshotLength; i++) {
	thisLink = allLinks.snapshotItem(i);
	// do something with thisLink 
	oldHTML = thisLink.innerHTML;
	newHTML = oldHTML.replace(
		/%u([0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z])/g,"&#x$1;");	//for %uXXXX
	Try.these(
		function (){
			//for utf8 encoding
			newHTML = newHTML.replace(/((%[A-Z0-9][A-Z0-9])+)/g,
				function(str,p1,offset,flags){
					return decodeURIComponent(p1);
				}
			);
		}
	);	
	thisLink.innerHTML = newHTML;
}
